using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using DocumentManagement.Views;
using DocumentManagement.Models;

namespace DocumentManagement.Controllers
{
    [HandleError]
    public class TollController : BaseController
    {
        [Authentication(PermissionLevel.TollOperationList)]
        public ActionResult Index()
        {
            return View("index");
        }

        [Authentication(PermissionLevel.ChargeFromYuGuDan | PermissionLevel.ChargeFromGaoGao)]
        public ActionResult GetUnchargedBaoGaoAndYuGuDan()
        {
            var bgs = this.Model.GetUnchargedBaoGao(this.AuthenticatedUser.id);
            var ygds = this.Model.GetUnchargedYuGuDan(this.AuthenticatedUser.id);
            return View("UnchargedBaoGaoAndYuGuDan", new UnchargedBaoGaoAndYuGuDanViewData() { BGs = bgs, YGDs = ygds });
        }

        [Authentication(PermissionLevel.ChargeFromYuGuDan)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ChargeYuGuDan(Guid ygId, double shshje)
        {
            this.Model.ChargeYuGuDan(ygId, shshje);
            return RedirectToAction("GetUnchargedBaoGaoAndYuGuDan");
        }

        [Authentication(PermissionLevel.ChargeFromGaoGao)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ChargeBaoGao(Guid bgId, double shshje)
        {
            this.Model.ChargeBaoGao(bgId, shshje);
            return RedirectToAction("GetUnchargedBaoGaoAndYuGuDan");
        }

        [Authentication(PermissionLevel.ConfirmCharge)]
        public ActionResult ShowChargeConfirmation()
        {
            var bgs = this.Model.GetChargedBaoGao();
            var ygds = this.Model.GetChargedYuGuDan();
            return View("ChargeConfirmation", new ChargeConfirmationViewData() { BGs = bgs, YGDs = ygds });
        }

        [Authentication(PermissionLevel.ConfirmCharge)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ConfirmBaoGaoCharge(Guid bgId, DateTime shfrq)
        {
            this.Model.ConfirmBaoGaoCharge(bgId, shfrq);
            return RedirectToAction("ShowChargeConfirmation");
        }


        [Authentication(PermissionLevel.ConfirmCharge)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ConfirmYuGuDanCharge(Guid ygId, DateTime shfrq)
        {
            this.Model.ConfirmYuGuDanCharge(ygId, shfrq);
            return RedirectToAction("ShowChargeConfirmation");
        }
    }
}
